package com.yanqu.road.server.cmd.activity.huashigang;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.pb.huashigang.HuaShiGangProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.huashigang.HuaShiGangMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @Author wpj
 * @Date 2020/10/6
 */
@Cmd(code = GameProtocol.S_HUA_SHI_GANG_CHOOSE_PATRONS, desc = "花石纲选择门客")
public class ChooseUnexpectedPatronsCmd extends AbstractCommand {
    int index;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        HuaShiGangProto.ChooseUnexpectedPatronsReqMsg msg = HuaShiGangProto.ChooseUnexpectedPatronsReqMsg.parseFrom(packet.getBytes());
        index = msg.getIndex();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = HuaShiGangMgr.getActivityInfoRet(player);
        if (ret != 0) {
            return;
        }
        ActivityInfo activityInfo = HuaShiGangMgr.getActivityInfo();
        if (!ActivityMgr.activityInTime(activityInfo)) {
            ret = GameErrorCode.E_HUA_SHI_GAG_NOT_IN_FIGHT_TIME;
            return;
        }
        HuaShiGangProto.CrossChooseUnexpectedPatronsReqMsg.Builder builder = HuaShiGangProto.CrossChooseUnexpectedPatronsReqMsg.newBuilder();
        builder.setIndex(index);
        builder.setActivityId(activityInfo.getActivityId());
        player.sendPacket(CrossProtocol.C2_HUA_SHI_GANG_CHOOSE_PATRONS, builder);


    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            HuaShiGangProto.ChooseUnexpectedPatronsRespMsg.Builder builder = HuaShiGangProto.ChooseUnexpectedPatronsRespMsg.newBuilder();
            builder.setRet(GameErrorCode.E_ACTIVITY_NO_FOUND);
            player.sendPacket(ClientProtocol.U_HUA_SHI_GANG_CHOOSE_NEXT_POINT, builder);
        }
    }
}
